<?php
session_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include 'includes/header.php';
my_header('Казина :: Jwakk');
?>
			
			<div class="line"></div>
			<div class="mainConteiner">
			
			<?php include 'includes'.DIRECTORY_SEPARATOR.'top.php'; ?>
			<div class="topDelimiter"></div>
			
			<div class="content">
			
			<table cellspacing="0" cellpadding="0" width="100%"><tr>
			
			<td class="Mainmenu" valign="top">
                            <a href="index.php"><div class="manuB">Казина</div></a>
                            <a href="buyCasino.php"><div class="manuB">Купи казино</div></a>
                            <a href="yoursC.php"><div class="manuB">Твои казина</div></a>
                            <a href="fight.php"><div class="manuB">Сбий се</div></a>
                            <a href="work.php"><div class="manuB">Работа</div></a>
                            <a href="zalozi.php"><div class="manuB">Залози</div></a>
                            <a href="coffee.php"><div class="manuB">Градът</div></a>
                            <a href="profile.php?user=<?php echo $_SESSION['user_info']['user']; ?>"><div class="manuB">Профил</div></a>
                            <?php
								$mes_q = mysql_query('SELECT id FROM message WHERE `do`="'.$_SESSION['user_info']['user'].'" AND `read`="0"');
								$mes_n = mysql_num_rows($mes_q);
								echo '<a href="mail.php"><div class="manuOnB">Съобщения ['.$mes_n.']</div></a>';
							?>
                            <a href="index.php?logout"><div class="manuBLogOut">Изход</div></a>

                            <br/>
                            <a href="#"><img alt="Последвайте Jwakk в Facebook" src="img/facebook.png" /></a>
                            <a href="#"><img alt="Последвайте Jwakk в Twitter" src="img/twitter.png" /></a>
                            <a href="#"><img alt="Абонирайте се за RSS емисии" src="img/rss.png" /></a>
                        </td>
				
				<td valign="top">
					<div class="gameBorder">
					<div class="TheGame">
					<div class="gameTitle">Лични съобщения</div>	
					<br/>
					
					<a href="mail.php" class="tab">Входящи</a> <a href="mail.php?send" class="tab">Изпарти</a> 
					<div class="del"></div>
					<?php
						if(!isset($_GET['send'])){
							$message_q = mysql_query('SELECT * FROM message WHERE `do`="'.$_SESSION['user_info']['user'].'" ORDER BY date DESC');
							while($message_f = mysql_fetch_assoc($message_q)){
								if($message_f['read']==0){
									echo '<div class="casinostat"> <img alt="letter" title="прочетено" src="img/opend.png"/> &nbsp; <a href="letter.php?id='.$message_f['id'].'"> '.$message_f['title'].'</a> <a href="#"  style="float: right;">От: '.$message_f['ot'].'</a></div>';
								}
								elseif($message_f['read']==1){
									echo '<div class="casinostatN"> <img alt="letter" title="непрочетено" src="img/letter.png"/> &nbsp;   <a href="letter.php?id='.$message_f['id'].'" class="readed"> '.$message_f['title'].'</a> <a href="#" style="float: right;">От: '.$message_f['ot'].'</a></div>';
								}
							}
						}
						elseif(isset($_GET['send'])){
							if($_POST['massage_sub']!=1){
								echo '
								<form method="post" class="sendT">
									<span>До:</span><br/>
									<input class="textF2" style="width:550px;" type="text" name="to" value="'.$_GET['to'].'"/><br/>  <div></div>
									<span>Тема:</span><br/>
									<input class="textF2" style="width:550px;" type="text" name="tema"/><br/>  <div></div>
																
									<span>Съобщение:</span><br/>
									<textarea class="textF2" style="width:550px;height: 200px;" type="text" name="desc"></textarea><br/>  <div></div>
									<input class="but" type="submit" value="Изпрати" name="sub"/>
									<input type="hidden" name="massage_sub" value="1" />
								</form>
								';
							}
							elseif($_POST['massage_sub']==1){
								$to = $_POST['to'];
								$tema = $_POST['tema'];
								$desc = nl2br($_POST['desc']);
								$ot = $_SESSION['user_info']['user'];
								
								$to_q = mysql_query('SELECT id FROM users WHERE user="'.$to.'"');
									if(mysql_num_rows($to_q)==0){
										$m_error[1]='Няма такъв потребител.<br />';
									}
									if(strlen($tema)<2){
										$m_error[2]='Темата е твърде кратка.<br />';
									}
									if(strlen($tema)>50){
										$m_error[3]='Темата е твърде дълга.<br />';
									}
									if(strlen($desc)==0){
										$m_error[4]='Съобщението не може да бъде празно.<br />';
									}
										if(count($m_error)==0){
											mysql_query('INSERT INTO message(title,message,ot,do,date) 
											VALUES("'.$tema.'","'.$desc.'","'.$ot.'","'.$to.'",'.time().')');
											if(!mysql_error()){
												echo '<div class="access">Съобщението е успешно изпратено.</div>
												<br/>
												<a href="mail.php" class="but">Назад</a>
												<br/>
												<br/>
												';
												
											}
										}
										else{
											echo '<div class="overLevel"><h3>Грешка:<br/><br/></h3>';
											echo '<ul type="square">';
											foreach($m_error as $v){
												echo '<li><span>'.$v.'</span></li>';
											}
											echo '</ul></div>
											
												<br/>
												<a href="mail.php" class="but">Назад</a>
												<br/>
												<br/>
											';
										}
							}
							
							
						}
					?>
					
					
					
					<?php
						if(!isset($_GET['send'])){
							echo '
						<div class="padination">
							<br/>
							<i>Страници:</i> <a href="#">1</a> <a href="#">2</a> <span href="#">3</span> <a href="#">4</a> <a href="#">5</a> <i>....</i> <a href="#">22</a> 
						</div>
							';
						}
					?>
					
					</div>
					</div>
					<div class="help"> <a href="#">Помощ</a> | <a href="#">FAQ</a> | <a href="#">Условия</a> | <a href="#">Facebook</a></div>
				</td>
			
			</tr></table>
			
			
			<div class="footer">
				© JwakK.com · Всички права запазени · <a href="#">Условия за ползване</a>
			</div>
			</div>
			</div>
			
			<div class="bottom"></div>
			
			</body>
			</html>